package com.lms.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lms.domain.Profile;
import com.lms.domain.User;
import com.lms.dto.ProfileDto;
import com.lms.dto.ProfileMapper;

@Controller
public class ProfileController {
	
	@Autowired
	private com.lms.service.UserService service;
	
	@RequestMapping(value="/loadProfile")
	public @ResponseBody Profile loadProfile(@RequestParam String pan) {
		
		Profile profile = new Profile();
		profile.setPanNo(pan);
		profile = service.readProfile(profile);
		
		return profile;
	}
	
	@RequestMapping(value="/editProfile", method=RequestMethod.POST)
	public @ResponseBody ProfileDto editProfile(
			@RequestParam String firstName,
			@RequestParam String lastName,
			@RequestParam String address,
			@RequestParam String phone,
			@RequestParam String panNo) {

		
		
		Profile newProfile = new Profile();
		newProfile.setFirstName(firstName);
		newProfile.setLastName(lastName);
		newProfile.setAddress(address);
		newProfile.setPhone(phone);
		newProfile.setPanNo(panNo);
		
		
	
		
		return ProfileMapper.mapProfile(service.updateProfile(newProfile));
	}
}
